Repository navigation
fix: match an indented template line's indent exactly (#30) - #125
Merged
Merged
Conversation
GenerateRegexFromVariables ran the line's leading whitespace through
escapeText, which turns any run of spaces or tabs into [ \t]+, so a line
indented by two spaces also matched one space, four spaces or a tab.
Python TTP rebuilds the indent verbatim ("\n" + indent + ...). The
indent is now emitted literally and the rest of the line is built as
before.
Suite cases filed under #30 now fail later: test_issue_45* at #28,
test_slack_answer_2 at #63, and the route-target cases at three new
issues (#118, #119, #120).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
So the editor matches indented template lines the same way as the library and CLI after the #30 fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
roc-ops
force-pushed
the
fix/30-exact-indent
branch
from
November 28, 2026 01:50
85133de to
7a36ac0
Compare
Owner
Author
|
Rebased onto main after #116 (#35) merged. Changes:
Ran locally: go vet, go test, go test -race (without test/memory), staticcheck and the wasm build. All pass. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
An indented template line now matches data with exactly that indent, as in Python TTP 0.10.1, which builds the regex as
\n+ the template's leading whitespace + the rest of the line.Data
H,a,b,\tc,xagainstH {{ _start_ }}/{{ v | joinmatches }}(the #30 repro):v"a\nb\nc\nx""a""a"The fix is in
internal/pattern/engine.go,GenerateRegexFromVariables. The leading whitespace used to go throughescapeText, which turns every run of spaces or tabs into[ \t]+. It is now split off and emitted literally (spaces and tabs need no escaping), and the rest of the line is built as before. Whitespace inside a line still matches any run of spaces and tabs, as in TTP. Every compile path goes through this function, and all runtime match loops keep the data line's leading whitespace (they only right-trim it), so nothing else needed changing.Left as they were:
{{ _start_ }}/{{ _end_ }}lines. The runtime right-trims every data line, so a whitespace-only line arrives as""and has no indent to check. Filed as TTP compat: An indented standalone {{ _start_ }}/{{ _end_ }} matches any blank line, not only lines with that indent #121.Evidence
New
internal/pattern/indent_test.go(22 cases) covers exact indents, deeper and shallower indents, tab versus spaces,_start_,_line_,ignore, mid-line whitespace and unindented lines. Before the fix 7 cases failed, all of them matching data that TTP rejects.Repo-wide check for templates that relied on the loose matching:
go test ./...passes withGOTTP_PYTHONset to TTP 0.10.1, includingtest/comparison, which compares against live TTP.examples/*print the same output, apart from the serialized regex text inexamples/serialize.test/memoryproduction templates (show_cable-modem,show_log,show_ha_error-detection) give byte-identical results.ttpsuite (checked case by case against a main build):
None of the six suite cases filed under Indented template lines match data at any indentation #30 passes yet. Each now gets past the indent problem and fails on another issue, so its entry points at that issue:
test_issue_45,test_issue_45_1,test_issue_45_filtering_fixforwarding-options { {{ _start_ }}has no variables)test_github_issue_42test_github_issue_42_answer_start_line matches inside a sibling group)test_group_same_null_path_for_several_groupsjoinmatcheskeeps collecting after a sibling's_start_)test_slack_answer_2(TTP compat: Nested-section templates from TTP answers diverge; root cause not isolated #100) now gets through its nested sections. Its template comment says it depends on indentation ("exit {{end}} had wrong indentation level"). It now fails first on TTP compat: set(True) / set(False) (and any literal argument) is a string #63 (set(true)gives a string). The README table is updated to match.A sibling-group template that was wrong on main and now matches TTP:
vrf x / import / 1 / 2 / export / 3used to giveimp.rt = "import",exp.rt = "export", because the 3-space line matched the 2-space header lines. It now givesimp.rt = "1",exp.rt = "3", as TTP does.go vet,go test -race(withouttest/memory), staticcheck 2025.1.1 andGOOS=js GOARCH=wasm go buildall pass locally.Merge Danger
SaveCompiledTemplatestores each regex string, and loading reuses it without recompiling. Templates saved before this change keep the loose regex until they are compiled again. The format has no version field.CHANGELOG.md[Unreleased]and the same rows oftest/ttpsuite/README.md. Keep both sides. With both PRs merged,test_answers_and_docs/test_issue_50passes: fix: honor the characters argument of strip/lstrip/rstrip (#35) #116 points it at Indented template lines match data at any indentation #30, and this PR fixes Indented template lines match data at any indentation #30. The PR that merges second must delete that entry fromknown_failures.json. Combined result: suite pass 49 / skipped-by-issue 147 / design 4, repros pass 3 / 7.editor/gottp.wasmandeditor/js/gottp.wasmare checked-in builds and aren't rebuilt here, so the editor keeps the old matching until its wasm is rebuilt.Fixes #30
🤖 Generated with Claude Code